﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcApplication1.Models;

namespace Ligas.Tests.Fakes
{
    class FakeRepositorioForo : FakeRepositorioBase, IRepositorioForo
    {
        private List<Comentario> comentarios;
        private List<Topic> topics;

        public FakeRepositorioForo(List<Topic> topics, List<Comentario> comentarios)
        {
            this.topics = topics;
            this.comentarios = comentarios;
        }

        public void AgregarComentario(Comentario c)
        {
            comentarios.Add(c);
        }

        public void AgregarTopic(Topic t)
        {
            topics.Add(t);
        }

        public void EliminarComentario(Comentario c)
        {
            comentarios.Remove(c);
        }

        public void EliminarTopic(Topic t)
        {
            topics.Remove(t);
        }

        public Comentario getComentario(int indice)
        {
            return comentarios.SingleOrDefault(d => d.IDComentario == indice);
        }

        public Topic getTopic(int indice)
        {
            return topics.SingleOrDefault(d => d.IDTopic == indice);
        }

        public IQueryable<Comentario> TodosLosComentarios()
        {
            return comentarios.AsQueryable();
        }

        public IQueryable<Topic> TodosLosTopics()
        {
            return topics.AsQueryable();
        }

        public override void Save()
        {
            foreach (Topic t in topics)
                if (!t.EsValido)
                    throw new ApplicationException("Violacion de Reglas");
            foreach (Comentario c in comentarios)
                if (!c.EsValido)
                    throw new ApplicationException("Violacion de Reglas");
        }
    }
}
